<template>
  <div class="app-container flex-col minH">
    <div class="topline w100p bgwhite pt20 pb10 radius10 pl10 pr20 justify-between">
      <div class="align-center flex-wrap">
        <el-input v-model="uid" style="width: 280px" placeholder="搜尋收入用戶ID..." :prefix-icon="Search" class="search mr10 mb10" />

        <!-- <el-select v-model="type" placeholder="選擇收支類型" size="large" style="width: 240px" class="mr10 mb10">

          <el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select> -->
        <el-select v-model="action" placeholder="選擇收入類型" size="large" style="width: 240px" class="mr10 mb10">
          <el-option v-for="item in actionOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <el-select v-model="money_type" placeholder="選擇錢包類型" size="large" style="width: 240px" class="mr10 mb10">
          <el-option v-for="item in moneyOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <div class="align-center mb10">
          <el-date-picker v-model="start" type="datetime" placeholder="开始时间" value-format="YYYY-MM-DD HH:mm:ss" />
          <span class="plr10 clr9fa">--</span>
          <el-date-picker v-model="end" type="datetime" placeholder="结束时间" value-format="YYYY-MM-DD HH:mm:ss" />
        </div>

      </div>
      <div class="noshrink mb10">
        <el-button class="btn2" @click="getIncomeList()">查詢</el-button>
        <el-button class="btn1" @click="reset()">重置</el-button>
      </div>
    </div>
    <!-- <div class="bgblueg ptb20 radius10 w100p mt15 pl10 bold clr3c4">
      總金額：933078.30元

    </div> -->
    <div class="mt15 radius10 hidden pb15 flex1 bgwhite  flex-col w100p">
      <div class="flex1 w100p ">
        <el-table :data="tableData" style="width: 100%" cell-class-name="tbcell" header-cell-class-name="hdcell">
          <el-table-column prop="action_text" label="收入類型" width="200" />

          <el-table-column prop="uid" label="收入用戶" width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.user.id)">{{ scope.row.user.phone }}(ID:{{ scope.row.user.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="uid" label="來源用戶" width="200">
            <template #default="scope">
              <span @click="showUser(scope.row.fromuser.id)">{{ scope.row.fromuser.phone }}(ID:{{ scope.row.fromuser.id }})</span>

            </template>
          </el-table-column>
          <el-table-column prop="money_type_text" label="錢包類型" min-width="100" />
          <el-table-column prop="money" label="金額" min-width="100">
          </el-table-column>
          <el-table-column prop="created_at" label="創建時間" sortable min-width="200" />
        </el-table>
      </div>
      <div class="plr20 mlauto mt20">
        <el-pagination v-model:current-page="currentPage" prev-text="上一頁" next-text="下一頁" :default-page-size="15" :small="small" :disabled="disabled" :background="true" layout="prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
      </div>

    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { incomeList } from '@/api/finance.js'
import { inject } from 'vue';
const showUser = inject('showUser');
onMounted(() => {
  getIncomeList()
})

// 消费记录列表
const getIncomeList = () => {
  incomeList({
    page: currentPage.value,
    uid: uid.value,
    type: type.value,
    money_type: money_type.value,
    start: start.value,
    end: end.value,
    action: action.value
  }).then((res) => {
    console.log('消费记录列表', res)
    tableData.value = res.data.data
    total.value = res.data.total
  })
}
const reset = () => {
  uid.value = ''
  type.value = ''
  money_type.value = ''
  start.value = ''
  end.value = ''
  action.value = ''
  getIncomeList()
}
const uid = ref('')
const type = ref('')
const money_type = ref('')
const start = ref('')
const end = ref('')
const action = ref('')

const moneyOptions = [
  {
    label: '訂單錢包',
    value: '1'
  },
  {
    label: '車費錢包',
    value: '2'
  },
  {
    label: '打赏錢包',
    value: '3'
  },
  {
    label: '邀請錢包',
    value: '4'
  },
]
const actionOptions = [
  {
    label: '車費單',
    value: '1'
  },
  {
    label: '服務單',
    value: '2'
  },
  {
    label: '打赏',
    value: '3'
  },
  {
    label: '邀請訂單返佣',
    value: '4'
  },
]
const typeOptions = [
  {
    label: '支出',
    value: '0'
  },
  {
    label: '收入',
    value: '1'
  },
]
const tableData = ref([])
const tableRowClassName = () => {
  return 'tbrow'
}
const currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
  getIncomeList()
}
const router = useRouter()
const toAdd = () => {
  console.log(router)
  router.push({ path: 'addNotice' })
}
const edit = (type) => {
  router.push({ path: 'signEdit' })
}
</script>

<style lang="scss" scoped>
.search {
  overflow: hidden;
  border-radius: 10px !important;
  // padding: 5px 0px;
}
</style>
<style></style>
 